package com.usian.service.impl;

import com.usian.mapper.UserMapper;
import com.usian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.usian.service.UserService;

import java.util.List;

@SuppressWarnings("ALL")
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public List<User> findAll() {

        //查询数据库中数据
        List<User> userList = userMapper.findAll();


        return userList;
    }

    @Override
    public User findById(Integer id) {
        User user = userMapper.selectById(id);
        return user;
    }

    /*@Override
    public void add(Integer id, String userName, String password, String address, String inputDate, Integer roleld) {
        User user = new User();
        user.setId(id);
        user.setUserName(userName);
        user.setPassword(password);
        user.setAddress(address);

        *//*SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(inputDate);
        try {
            Date parse = (Date) simpleDateFormat.parse(format);
            user.setInputDate(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }*//*
        user.setInputDate(Date.valueOf(inputDate));

        user.setRoleld(roleld);
        userMapper.insertSelective(user);
//        userMapper.insertSelective(user);
    }*/

    @Override
    public void del(Integer id) {
        userMapper.deleteById(id);
    }

    @Override
    public void addUser(User user) {
        userMapper.insert(user);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }


    //根据用户名和密码
    @Override
    public User findByNameAndPwd(String userName, String password) {
        User user=userMapper.findByNameAndPwd(userName,password);
        return user;
    }

}
